
cc.Class({
  extends: cc.Component,

  properties: {
    enemyPre: cc.Prefab,
    enemyDtJson: cc.JsonAsset,
  },


  onLoad() {
    this.schedule(this.createEnemy, 1);
    this.createEnemy();
  },

  start() {

  },

  update(dt) {

  },

  createEnemy() {
    let enemyNode = cc.instantiate(this.enemyPre);
    enemyNode.parent = this.node;
    let enemyJs = enemyNode.getComponent("Enemy");

    //产生的是哪个敌机
    let index = Math.floor(Math.random() * (this.enemyDtJson.json.length - 0) + 0);
    let enemyDt = this.enemyDtJson.json[index];
    enemyJs.initWithDt(enemyDt);

    //设置敌机产生的位置
    let minX = -cc.winSize.width / 2 + enemyNode.width / 2;
    let maxX = cc.winSize.width / 2 - enemyNode.width / 2;
    enemyNode.x = Math.random() * (maxX - minX) + minX;
    enemyNode.y = cc.winSize.height / 2 + enemyNode.height / 2;
    enemyJs.enemyMove();
  }
});
